﻿@model BusinessLayer.VDataEntities.VPromoterProvinceMappings

@{
    ViewBag.Title = "实验员详情";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
<div class="mainCont">
    <div class="" style="position:fixed;margin-top:-30px;cursor:pointer">
        <a onclick="location.href='@TrialManagementTool.Helper.UrlHelper.alterContent("Promoter/Index")'"> <img src="@TrialManagementTool.Helper.UrlHelper.alterContent("Images/return.png")" />
            <span style="color:#00985f">返回</span>
        </a>

    </div>
    <table class="table table-bordered">
        <tr>
            <td width="150px" style="text-align:center">
                人员
            </td>
            <td style="padding-left:30px">
                @Model.Promoter.ChineseName
                <input type="hidden" value=@Model.Promoter.ID id="promoter_id" />
            </td>
        </tr>
        <tr>
            <td style="text-align:center">
                已有地点
            </td>
            <td id="existcity" style="padding-left:25px">
                <div class="existCityDiv"></div>
                @for (int i = 0; i < Model.Provinces.Count(); i++)
                {
                    <div class="rounddiv" id=@("CityMapping_" + Model.Provinces[i].ID)>
                        <span> @Model.Provinces[i].Name</span>
                        <div style="position:absolute;top:0;right:0;font-size:10px;height:25px">
                            <img src="@TrialManagementTool.Helper.UrlHelper.alterContent("Images/del.png")" style="height:15px;margin-top:-30px;cursor:pointer;" onclick="DelCity(@Model.Provinces[i].ID)" />
                        </div>
                    </div>
                }
            </td>
        </tr>
        <tr>
            <td style="text-align:center">可添加地点</td>
            <td style="padding-left:20px">
                <input type="hidden" id="ProvinceId" value="0" />
                <div class="provinceSelect" id="province">
                    <ul></ul>
                </div>
            </td>
        </tr>
    </table>
</div>

<script>
    $().ready(function () {
        GetProvince();
    })

    $(".provinceSelect ul").delegate("a", "click", function () {
        if ($("#existcity").text().indexOf($(this).text()) > 0) {
            AlertErrorBox($(this).text() + "已存在");
        } else {
            //add city
            $.ajax({
                url: fixUrl("api/Promoter/AddCityToPromoter"),
                type: "get",
                data: { cityID: $(this).data("value"), PromterID: $("#promoter_id").val() },
                success: function (data) {
                    AlertCompleteBox("添加成功");
                }
            });
            var template = "<div class=\"rounddiv\" id=\"CityMapping_" + $(this).data("value") + "\"><span> " + $(this).text() + "</span><div style=\"position:absolute;top:0;right:0;font-size:10px;height:25px\"><img src=" + '@TrialManagementTool.Helper.UrlHelper.alterContent("Images/del.png")' + " style=\"height:15px;margin-top:-30px;cursor:pointer;\" onclick=\"DelCity(" + $(this).data("value") + ")\" /> </div></div>";
            //hide city
            if ($(".existCityDiv").children().length == 1) {
                $(".existCityDiv").after(template);
            } else {
                $("#existcity").children().last().after(template);
            }
        }
    })

    function GetProvince() {
        $.ajax({
            url: fixUrl("api/Common/GetAllProvince"),
            success: function (data) {
                $(".provinceSelect ul").html("");
                for (var i = 0; i < data.length; i++) {
                    $(".provinceSelect ul").append("<li> <a href='#none' data-value=" + data[i].ID + ">" + data[i].Name + "</a></li>");
                }
            }
        });
    }

    function DelCity(id) {
        $("#CityMapping_" + id).remove();
        $.ajax({
            url: fixUrl("api/Promoter/DelCityMapping"),
            type: "post",
            data: { ID: $("#promoter_id").val(), CityID: id },
            success: function (data) {
                AlertCompleteBox("删除成功");
            }
        });
    }

</script>